#include <stdio.h>
#include <conio.h>
#include <string.h>
void swapstr(char *s1,char *s2)
{
	char t[20];
	strcpy(t,s1);
	strcpy(s1,s2);
	strcpy(s2,t);
}

int partition(char nam[20][20],int low,int high)
{
	int i,k,r,pivot;
	pivot=low;
	r=(high-low)/2;
	for(k=0;k<=r;k++)	{
		for(i=high;i>low;i--)	{
			if(strcmp(nam[low],nam[i])>0)	{
				swapstr(nam[low],nam[i]);
				low++;
				high=i;
				pivot=i;
				break;
			}
		}
		if(i==low)
			break;
		for(i=low;i<high;i++)	{
			if(strcmp(nam[i],nam[high])>0)	{
				swapstr(nam[i],nam[high]);
				high--;
				low=i;
				pivot=i;
				break;
			}
		}
		if(i==high)
			break;
	}
	return pivot;
}

void quick(char nam[20][20],int low,int high)
{
	int m,pivot;
	m=high;
	pivot=partition(nam,low,high);
	high=pivot-1;
	if(low<high)
		quick(nam,low,high);
	low=pivot+1;
	high=m;
	if(low<high)
		quick(nam,low,high);
}

void main()
{
	char nam[20][20];
	int i,n;
	clrscr();
	printf("\nEnter the number of elements:");
	scanf("%d",&n);
	for(i=0;i<n;i++)	{
		printf("\nElement(%d)",i+1);
		scanf("%s",nam[i]);
	}
	quick(nam,0,n-1);
	for(i=0;i<n;i++)	{
		printf("\n-%s",nam[i]);
	}
	getch();
}